package org.example.cloudprovidercontroller8002.config;

import com.atomikos.jdbc.AtomikosDataSourceBean;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.mysql.cj.jdbc.MysqlXADataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.example.cloudprovidercontroller8002.pojo.DBConfig1;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@MapperScan
public class Test {

    @Bean("DataSource1")
    public DataSource salveDataSource(DBConfig1 dbConfig1){
        AtomikosDataSourceBean sourceBean = new AtomikosDataSourceBean();

        MysqlXADataSource mysqlXADataSource = new MysqlXADataSource();

        sourceBean.setXaDataSource(mysqlXADataSource);

        return null;
    }

    public SqlSessionFactory sqlSessionFactory(@Qualifier("DataSource1") DataSource dataSource) throws Exception {
        MybatisSqlSessionFactoryBean sessionFactoryBean = new MybatisSqlSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource);
        return sessionFactoryBean.getObject();
    }

    public void method() throws Exception {
        AtomikosDataSourceBean sourceBean = new AtomikosDataSourceBean();

        MysqlXADataSource mysqlXADataSource = new MysqlXADataSource();

        MybatisSqlSessionFactoryBean sessionFactoryBean = new MybatisSqlSessionFactoryBean();

        SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sessionFactoryBean.getObject());
    }



}
